﻿Public Partial Class Theme
    Inherits System.Web.UI.Page

    Dim clsGet As New ClassFunctionGetData
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Private Sub btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click
        ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " parent.location.reload();", True)
    End Sub

    Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Dim conn As New System.Data.SqlClient.SqlConnection(connString)
        Dim clsDB As New ClassDatabase
        Dim clsFc As New ClassFunction
        Dim condition As Boolean = True
        Dim tran As System.Data.SqlClient.SqlTransaction = Nothing
        Dim User_Modify As String = CType(Session("UserData"), DataSet).Tables(0).Rows(0).Item("User_name")
        Dim Master_P As String = "D"
        If radio1.Checked Then
            Master_P = "D"
        ElseIf radio2.Checked Then
            Master_P = "B"
        ElseIf radio3.Checked Then
            Master_P = "O"
        ElseIf radio4.Checked Then
            Master_P = "V"
        ElseIf radio5.Checked Then
            Master_P = "E"
        End If
        Application.Lock()
        conn.Open()
        Dim A_Code As String = clsDB.GeneratorID(conn, "Action_Operation")
        tran = clsDB.BeginTran(conn)

        If (clsFc.InsertUserMASTER_P(CType(Session("UserData"), DataSet).Tables(0).Rows(0).Item("User_name"), Master_P, conn, tran) < 1) Then
            condition = False
        End If
        If (condition) Then
            clsDB.CommitTran(tran)
            'ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " parent.closeModalTheme();", True)
            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " parent.location.reload();", True)

        Else
            clsDB.RollBackTran(tran)
            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('เกิดความผิดพลาดในการบันทึก');", True)
        End If
        Application.UnLock()
        conn.Dispose()

    End Sub

    Private Sub radio1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles radio1.CheckedChanged
        If (radio1.Checked) Then
            radio2.Checked = False
            radio3.Checked = False
            radio4.Checked = False
        End If
    End Sub

    Private Sub radio2_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles radio2.CheckedChanged
        If (radio2.Checked) Then
            radio1.Checked = False
            radio3.Checked = False
            radio4.Checked = False
        End If
    End Sub

    Private Sub radio3_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles radio3.CheckedChanged
        If (radio3.Checked) Then
            radio1.Checked = False
            radio2.Checked = False
            radio4.Checked = False
        End If
    End Sub

    Private Sub MainPage_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        Dim ds As DataSet = Session("UserData")
        If Not (ds Is Nothing) Then
            Page.MasterPageFile = clsGet.GetMaster_Page(ds.Tables(0).Rows(0).Item("User_Name").ToString(), "")
        End If
    End Sub
End Class